package com.ks.gopush.cli.utils;

import com.ks.gopush.cli.PushMessage;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by gustavo on 2015/4/29.
 */
public class ParserUtils {

    /**
     *
     * @param jsonObject
     * @return
     */
    public static PushMessage parsePushMessage(JSONObject jsonObject){
        PushMessage message = new PushMessage();
        try {
            if(jsonObject.has("mid")){
                message.setMid(jsonObject.getLong("mid"));
            }
            if(jsonObject.has("gid")){
                message.setGid(jsonObject.getInt("gid"));
            }
            if(jsonObject.has("msg")){
                message.setMsg(jsonObject.getString("msg"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return message;
    }
}
